<!DOCTYPE html>
<html lang="zh-cn">

<head><title>
    Go | 
    
    ZZY2357 的博客</title>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="description" content="ZZY2357 的博客
    ">


<meta property="og:title" content="go" />
<meta property="og:description" content="ZZY2357 的博客" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://zzy2357.gitee.io/tags/go/" />
<meta property="og:updated_time" content="2020-06-11T20:15:43+08:00" />

<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="go"/>
<meta name="twitter:description" content="ZZY2357 的博客"/>

<meta itemprop="name" content="go">
<meta itemprop="description" content="ZZY2357 的博客">
<link rel="canonical" href="https://zzy2357.gitee.io/tags/go/" />

<link rel="icon" type="image/png" href="https://zzy2357.gitee.io/image/favicon.ico">

<link rel="stylesheet" href="/css/font-awesome.min.css">
<link rel="stylesheet" href="/css/bulma.min.css">





<script src=/js/ramium.js></script>
<link rel="stylesheet" href=/css/ramium.css>





</head>

<body><nav class="navbar is-dark" role="navigation" aria-label="main navigation">
  <div class="navbar-brand">
    <a class="navbar-item" href=/>
      
      <strong>ZZY2357 的博客 </strong>
      
    </a>

    <a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false"
      data-target="navbarBasicExample">
      <span aria-hidden="true"></span>
      <span aria-hidden="true"></span>
      <span aria-hidden="true"></span>
    </a>
  </div>

  <div id="navbarBasicExample" class="navbar-menu">
    <div class="navbar-start">
      
      
      <a class="navbar-item" href="/">主页</a>
      
      
      
      <div class="navbar-item has-dropdown is-hoverable">
        <a class="navbar-link">博客</a>
        <div class="navbar-dropdown">
          
          <a class="navbar-item" href="/tags/">所有标签</a>
          
          <a class="navbar-item" href="/posts/">所有文章</a>
          
        </div>
      </div>
      
      
      
      <a class="navbar-item" href="/about/">关于</a>
      
      
      
      <a class="navbar-item" href="/index.xml">RSS</a>
      
      
    </div>

    <div class="navbar-end">
      
      <a class="navbar-item navgithub" href="https://github.com/zzy2357" target="_blank">
        <i class="fa fa-github fa-2x"></i>
      </a>
      

      
    </div>
  </div>
</nav><div class="columns is-centered">
        <div id="page-body" class="column is-7">

<div class="content">
    <h1>Go</h1>
</div>

<div class="blog-brief">
    <a href="/posts/simple-gin-json-server/">
        <h3 class="title is-4">
            使用 Go &#43; Gin 实现一个简单的 Json 服务器
        </h3>
    </a>

    <div class="level is-mobile details">
        <div class="level-left">

            
            <div class="level-item">
                <a href="/posts/simple-gin-json-server/">
                    <p class="subtitle info date">Jun 11, 2020
                    </p>
                </a>
            </div>
            


            <div class="level-item">
                <a href="/posts/simple-gin-json-server/">
                    <p class="subtitle info">
                        2 mins read
                    </p>
                </a>
            </div>
        </div>
        <div class="level-right is-hidden-touch">
            
            <a class="tag is-rounded" href="/tags/go">Go</a>
            
        </div>
    </div>

    <div>
        

        <div>
            <a href="/posts/simple-gin-json-server/">
                <p class="summary">
                    有时在学习前端的时候，不得不用一下一些 API，但是又找不到自己想要的数据，所以这个时候可以自己制作一个。这里我们使用 GO 语言和 Gin 框架来做一个。
搭建项目 cd $GOPATH/src/github.com/zzy2357 # 创建文件夹 mkdir simple-json-server cd ./simple-json-server # 初始化 Go Mod go mod init # 创建主文件 touch main.go 写代码 package main import ( // 导入模块 	&#34;github.com/gin-gonic/gin&#34; ) func main() { r := gin.Default() r.GET(&#34;/&#34;, func(c *gin.Context) { // 跨域设置  c.Header(&#34;Access-Control-Allow-Origin&#34;, &#34;*&#34;) // 200 状态码 	c.JSON(200, gin.H{ // Json 数据 	&#34;message&#34;: &#34;Hello world!&#34;, }) }) // 运行服务器，端口为 8000 	r.
                    
                </p>
            </a>
        </div>
    </div>

    <div class="level is-mobile continue-reading">
        <div class="level-left">
        </div>
        <div class="level-right">
            <a href="/posts/simple-gin-json-server/">Continue reading <i class="fa fa-angle-double-right"
                    aria-hidden="true"></i></a>
        </div>
    </div>
    <hr>
</div>





















        </div>
    </div>

<footer class="footer has-background-dark">
    <div class="content has-text-centered has-text-white">
        <p>
            © 2020 Ramium. Powered by
            <a class="has-text-light" href="https://github.com/gohugoio/hugo" target="_blank">
            Hugo</a>. Theme
            <a class="has-text-light" href="https://github.com/rafed123/ramium/" target="_blank">
                Ramium.
            </a>
        </p>
    </div>
</footer>
</body>

</html>